﻿using CNKI.TPI.Web.Admin.Model;
using CNKI.TPI.Web.Search.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CNKI.TPI.Web.Admin.IBLL
{
    /// <summary>
    /// 
    /// </summary>
    public enum RightType
    {
        /// <summary>
        /// 用户权限
        /// </summary>
        User = 0,
        /// <summary>
        /// 组权限
        /// </summary>
        Group = 1,
    };
    /// <summary>
    /// 用户管理服务
    /// </summary>
    public interface IUserMgmtService
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        IList<SYS_CMS_USER> GetUser(int pageIndex, int pageSize, out int count);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        IList<SYS_CMS_USER> GetUserByName(string userName, int pageIndex, int pageSize, out int count);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="groupID"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        IList<SYS_CMS_USER> GetUserByGroupID(int groupID, int pageIndex, int pageSize, out int count);
        /// <summary>
        /// 获取用户组
        /// </summary>
        /// <returns></returns>
        IList<SYS_CMS_GROUP> GetGroup();
        /// <summary>
        /// 根据用户组名称，查询用户组
        /// </summary>
        /// <param name="groupName"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        IList<SYS_CMS_GROUP> GetGroupByName(string groupName, int pageIndex, int pageSize, out int count);
        /// <summary>
        /// 根据用户id获取用户IP
        /// </summary>
        /// <returns></returns>
        IList<SYS_CMS_USER_IP> GetGroupIpByUserID(int userid);
          /// <summary>
        /// 根据用户租id获取用户组IP
        /// </summary>
        /// <returns></returns>
        IList<SYS_CMS_USER_IP> GetGroupIpByGroupID(int gid);
        /// <summary>
        /// 删除用户组
        /// </summary>
        /// <returns></returns>
        bool DeleteUserGroup(string sysid);

        /// <summary>
        /// 删除对应的ip段
        /// </summary>
        /// <returns></returns>
        bool DeleteUserIP(string sysidstr);
        /// <summary>
        /// 获取单位名称
        /// </summary>
        /// <returns></returns>
        IList<SYS_CMS_USER_UNIT> GetUnit();

        /// <summary>
        /// 获取部门
        /// </summary>
        /// <returns></returns>
        IList<SYS_CMS_USER_UNIT_DEPT> GetDeptByUnitID(int uid);
        /// <summary>
        /// 判断用户名是否存在
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        int IsExitUser(string userName);
        /// <summary>
        /// 获取密级
        /// </summary>
        /// <returns></returns>
        IList<SYS_CMS_SECURITY> GetSecurity();
        /// <summary>
        /// 保存用户相关信息
        /// </summary>
        /// <param name="userobj">用户</param>
        /// <param name="grouplist">用户组</param>
        /// <param name="iplist">用户IP</param>
        /// <returns></returns>
        int SaveUserInfo(SYS_CMS_USER userobj, IList<SYS_CMS_USER_GROUP> grouplist, IList<SYS_CMS_USER_IP> iplist);
        /// <summary>
        /// 删除对应的用户
        /// </summary>
        /// <returns></returns>
        bool DeleteUser(string sysidstr);
        /// <summary>
        /// 根据ID获取用户
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        SYS_CMS_USER GetUserInfoByID(int userid);
        /// <summary>
        /// 根据用户ID获取用户对应得用户组（逗号分隔的用户组ID）
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        string GetUserGroupID(int userid);
        /// <summary>
        /// 保存用户组
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="iplist"></param>
        /// <returns></returns>
        bool SaveGroup(SYS_CMS_GROUP obj, IList<SYS_CMS_USER_IP> iplist);
        /// <summary>
        /// 判断用户组是否存在
        /// </summary>
        /// <param name="name"></param>
        /// <param name="sysid"></param>
        /// <returns></returns>
        int IsExitUserGroup(string name, int sysid);
        /// <summary>
        /// 删除密级
        /// </summary>
        /// <param name="sysidstr"></param>
        /// <returns></returns>
        bool DeleteSecurity(string sysidstr);
        /// <summary>
        /// 判断密级重复
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="sysid"></param>
        /// <returns></returns>
        int IsExitSecurity(string name, string value, int sysid);
        /// <summary>
        /// 保存密级
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        bool SaveSecurity(SYS_CMS_SECURITY obj);
        /// <summary>
        /// 获取用户单位  分页
        /// </summary>
        /// <param name="unitname"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        IList<SYS_CMS_USER_UNIT> GetUnitPageSize(string unitname, int pageIndex, int pageSize, out int count);

        /// <summary>
        /// 保存用户单位
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        bool SaveUnitInfo(SYS_CMS_USER_UNIT obj);
        /// <summary>
        /// 删除用户单位
        /// </summary>
        /// <param name="sysidstr"></param>
        /// <returns></returns>
        bool DeleteUnit(string sysidstr);
        /// <summary>
        /// 判断单位名称是否存在
        /// </summary>
        /// <param name="name"></param>
        /// <param name="sysid"></param>
        /// <returns></returns>
        int IsExitUnit(string name, int sysid);
        /// <summary>
        /// 获取单位下的部门节点
        /// </summary>
        /// <param name="unitid">单位id</param>
        /// <param name="garde">节点级别</param>
        /// <param name="code">父节点code  当code为空时，即获取根节点</param>
        /// <returns></returns>
        IList<SYS_CMS_USER_UNIT_DEPT> GetDept(int unitid, int garde, string code);
        /// <summary>
        /// 删除部门
        /// </summary>
        /// <param name="sysid"></param>
        /// <param name="syscode"></param>
        /// <param name="unitid"></param>
        /// <returns></returns>
        bool DeleteDept(string sysid, string syscode, int unitid);
        /// <summary>
        /// 保存部门
        /// </summary>
        /// <param name="unitid">单位ID</param>
        /// <param name="sysid">主键，新增时传0</param>
        /// <param name="deptname"></param>
        /// <param name="parentcode">父节点code,当新增节点为根节点时传"000"</param>
        /// <param name="grade">当前节点的级别</param>
        /// <returns></returns>
        bool SaveDeptInfo(int unitid, int sysid, string deptname, string parentcode, int grade);
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        bool AddAllDBRight(int id, RightType rightType);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="dbID"></param>
        /// <param name="rightType"></param>
        /// <returns></returns>
        bool AddDBRight(int id, IList<int> dbID, RightType rightType);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="dbID"></param>
        /// <param name="rightType"></param>
        /// <returns></returns>
        bool AddDBRight(int id, int dbID, RightType rightType);
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        DataSet GetDBRightList(string id, int pageIndex, int pageSize, RightType rightType, string dbName, IList<SearchType> SearchTypeList = null);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="authdblist"></param>
        /// <param name="fieldlist"></param>
        /// <param name="daycount"></param>
        /// <param name="maxcount"></param>
        /// <param name="dbid"></param>
        /// <param name="userid"></param>
        /// <param name="rightType"></param>
        /// <param name="navstr"></param>
        /// <returns></returns>
        bool AuthSaveUser(string authdblist, string fieldlist, int daycount, int maxcount, int dbid, int userid, RightType rightType, string navstr);

        /// <summary>
        /// 获取用户权限数据
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="dbid"></param>
        /// <param name="rightType"></param>
        /// <returns></returns>
        SYS_CMS_USER_ACL_DB_RIGHT GetDBRight(int userid, int dbid, RightType rightType);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="dbId"></param>
        /// <param name="dbCode"></param>
        /// <param name="rightType"></param>
        /// <returns></returns>
        DataTable GetDBCLS(int userId, int dbId, string dbCode, RightType rightType);
    }
}
